<template>
	<view style="">
		
		<view class="all_project_head_btn" style="">
			<project-button :projectId="project_id" stageName="资质/印章使用申请"></project-button>
			<step-button :approvalLog="addFormData.approval_log" :processList="stepProcessList" v-if="addFormData.approval_log != null"></step-button>
		</view>
		
		<view style="padding-bottom: 200rpx;">
			<!-- 项目名称 -->
			<view class="info_item" style="border: 0;">
				<text class="all_text_title">项目名称</text>
				<textarea disabled v-model="S_project_name" maxlength="-1"
				:class="true?'all_new_input_disable_style':'all_new_input_style'"
					auto-height="true" style="width: 95%;padding: 18rpx;"
					 />
			</view>
			<!-- 项目编号 -->
			<view class="info_item" style="border: 0;">
				<text class="all_text_title">项目编号</text>
				<input
					style="margin-top: 39rpx;"
					placeholder-style="font-size:30rpx"
					:value="S_project_code"
					disabled
					:class="true?'all_new_input_disable_style':'all_new_input_style'"
				/>
			</view>
			<!-- 申请原因 -->
			<view class="info_item radioRow">
				<text class="all_text_title radioRowtitle ">申请原因</text>
				<radio-group @change="handleProjectTypeChange1" name="" class="radio radio_text">
					<label>
						<radio
							:checked="addFormData.reasons_application=='1'?true:false"
							:disabled="!isSubmit"
							:value="1"
							style="transform: scale(0.7);"
						/>
						<text>报告</text>
					</label>
					<label>
						<radio
							:checked="addFormData.reasons_application=='2'?true:false"
							:disabled="!isSubmit"
							:value="2"
							style="transform: scale(0.7);"
						/>
						<text>合同</text>
					</label>
					<label>
						<radio
							:checked="addFormData.reasons_application=='3'?true:false"
							:disabled="!isSubmit"
							:value="3"
							style="transform: scale(0.7);"
						/>
						<text>发票</text>
					</label>
					<label>
						<radio
							:checked="addFormData.reasons_application=='4'?true:false"
							:disabled="!isSubmit"
							:value="4"
							style="transform: scale(0.7);"
						/>
						<text>招投标</text>
					</label>
					<label>
						<radio
							:checked="addFormData.reasons_application=='-1'?true:false"
							:disabled="!isSubmit"
							:value="-1"
							style="transform: scale(0.7);"
						/>
						<text>其他</text>
					</label>
				</radio-group>
			</view>
			<!-- 其他原因 -->
			<view class="info_item" v-if="isTypeInputDis" style="border: 0;">
				<text class="all_text_title">其他原因</text>
				<input
					style="margin-top: 39rpx;"
					placeholder-style="font-size:30rpx"
					v-model="addFormData.reasons_application_else"
					:disabled="!isSubmit"
					:class="!isSubmit?'all_new_input_disable_style':'all_new_input_style'"
				/>
			</view>
			<!-- 印章类型 -->
			<view class="info_item radioRow">
				<text class="all_text_title radioRowtitle">印章类型</text>
				<radio-group @change="handleProjectTypeChange2" class="radio radio_text">
					<label>
						<radio
							:disabled="!isSubmit"
							:value="1"
							:checked="addFormData.seal_category=='1'?true:false"
							style="transform: scale(0.7);"
						/>
						<text>公章</text>
					</label>
					<label>
						<radio
							:disabled="!isSubmit"
							:value="2"
							:checked="addFormData.seal_category=='2'?true:false"
							style="transform: scale(0.7);"
						/>
						<text>法人章</text>
					</label>
					<label>
						<radio
							:disabled="!isSubmit"
							:value="3"
							:checked="addFormData.seal_category=='3'?true:false"
							style="transform: scale(0.7);"
						/>
						<text>合同专用章</text>
					</label>
					<label>
						<radio
							:disabled="!isSubmit"
							:value="4"
							:checked="addFormData.seal_category=='4'?true:false"
							style="transform: scale(0.7);"
						/>
						<text>报告专用章</text>
					</label>
				</radio-group>
			</view>
			<!-- 资质类型 -->
			<view class="info_item radioRow">
				<text class="all_text_title radioRowtitle">资质类型</text>
				<radio-group @change="handleProjectTypeChange3" class="radio radio_text">
					<label>
						<radio
							:disabled="!isSubmit"
							:value="1"
							:checked="addFormData.qualification_category=='1'?true:false"
							style="transform: scale(0.7);"
						/>
						<text>煤矿</text>
					</label>
					<label>
						<radio
							:disabled="!isSubmit"
							:value="2"
							:checked="addFormData.qualification_category=='2'?true:false"
							style="transform: scale(0.7);"
						/>
						<text>非煤</text>
					</label>
					<label>
						<radio
							:disabled="!isSubmit"
							:value="3"
							:checked="addFormData.qualification_category=='3'?true:false"
							style="transform: scale(0.7);"
						/>
						<text>营业执照</text>
					</label>
				</radio-group>
			</view>
			<!-- 用印数量 -->
			<view class="info_item" style="border: 0;">
				<text class="all_text_title">用印数量</text>
				<input
					style="margin-top: 39rpx;"
					placeholder-style="font-size:30rpx"
					:disabled="!isSubmit"
					v-model="addFormData.quantity_printed"
					:class="!isSubmit?'all_new_input_disable_style':'all_new_input_style'"
				/>
			</view>
			<!-- 项目负责人 -->
			<view class="info_item" style="border: 0;">
				<text class="all_text_title">项目负责人</text>
				<input
					style="margin-top: 39rpx;"
					placeholder-style="font-size:30rpx"
					disabled
					:value="S_contacts"
					:class="true?'all_new_input_disable_style':'all_new_input_style'"
				/>
			</view>
			<!-- 经办人 -->
			<view class="info_item" style="border: 0;">
				<text class="all_text_title">经办人</text>
				<input
					style="margin-top: 39rpx;"
					placeholder-style="font-size:30rpx"
					disabled
					:value="S_evaluators"
					:class="true?'all_new_input_disable_style':'all_new_input_style'"
				/>
			</view>
			<!-- 审批人 -->
			<view class="info_item" style="border: 0;">
				<text class="all_text_title">审批人</text>
				<input
					style="margin-top: 39rpx;"
					placeholder-style="font-size:30rpx"
					disabled
					:value="S_member"
					:class="true?'all_new_input_disable_style':'all_new_input_style'"
				/>
			</view>
			<!-- 备注 -->
			<view class="info_item" style="border-bottom: 0;">
				<text class="all_text_title">备注</text>
				<textarea
					class="textar"
					:disabled="!isSubmit"
					v-model="addFormData.remark"
					maxlength="-1"
					auto-height="true"
				/>
			</view>
			
			<!-- 附件上传提示 -->
			<view class="info_item" style="border-bottom: 0; color: #40A0F2;font-size: 26rpx;">
				*资质/印章使用申请：请上传最终版报告*
			</view>
			<!-- 附件上传 -->
			<view class="info_item" style="border: 0;">
				<upload-file
					:isSubmit="isSubmit"
					:imgList="addFormData.annex"
					:detailsImgList="detailsImgList"
					@my-upload-change="upLoadChange"
				></upload-file>
			</view>
			<!-- 审批备注 -->
			<view
				class="info_item"
				v-if="addFormData.is_approve == 1 && details_project_status == '44'"
				style="border-bottom: 0;"
			>
				<text class="all_text_title">审批备注</text>
				<textarea
					v-model="approval_remark"
					class="textera"
					maxlength="-1"
					auto-height="true"
				/>
			</view>
		</view>
		<view style="width: 100%;height: 200rpx;"></view>
		<!-- 底部按钮 -->
		<view class="bottom">
			<view v-if="addFormData.is_edit != '1'">
				<button
					class="bottom_btn"
					style="background: #CCCCCC; width: 380rpx;"
					form-type="reset"
					@click="handleSubmit('1')"
				>
					保存草稿
				</button>
				<button
					class="bottom_btn"
					style="background: linear-gradient(0deg, #037CE3, #2EB3FF); margin-top: -88rpx;margin-left: 50%;"
					form-type="submit"
					@click="handleSubmit('0')"
				>
					提交
				</button>
			</view>
			
			<!-- 可撤回时显示 -->
			<view class="bottom" v-if="addFormData.is_edit == 1 && addFormData.withdraw_status == 1 && addFormData.is_approve != 1">
				<button
					class="bottom_btn"
					@click="handleWithdraw()"
					style="background: #DD524D; width: 100%;"
					form-type="reset"
				>
					撤回
				</button>
			</view>
			
			<view v-if="addFormData.is_approve==1 && details_project_status=='44'">
				<button
					class="bottom_btn"
					style="background: #CCCCCC; width: 380rpx;"
					form-type="reset"
					 @click="handleExamine('-1')"
				>
					驳回
				</button>
				<button
					class="bottom_btn"
					style="background: linear-gradient(0deg, #037CE3, #2EB3FF); margin-top: -88rpx;margin-left: 50%;"
					form-type="submit"
					@click="handleExamine('1')"
				>
					审批通过
				</button>
			</view>
			
			<!-- 可撤回时显示 -->
			<view class="bottom2" v-if="addFormData.is_approve == 1 && addFormData.withdraw_status == 1">
				<button
					class="bottom_btn2"
					@click="handleWithdraw()"
					style="background: #FF5A5F; margin-left: 0;"
					form-type="reset"
				>
					撤回
				</button>
				<button
					class="bottom_btn2"
					@click="handleExamine('-1')"
					style="background: #CCCCCC;margin-left: 33%;"
					form-type="reset"
				>
					驳回
				</button>
				<button
					class="bottom_btn2"
					style="background: linear-gradient(0deg, #037CE3, #2EB3FF);margin-left: 66%;"
					@click="handleExamine('1')"
					form-type="submit"
				>
					审批通过
				</button>
			</view>
			
		</view>
	</view>
</template>

<script>
import xiaolu from '@/components/xiaolu-signature/index.vue';
import UploadFile from '@/components/upload-file.vue';
import ProjectButton from '@/components/project-button.vue';
import StepButton from '@/components/step-button.vue';
export default {
	components: {
		UploadFile,
		ProjectButton,
		StepButton,
		xiaolu
	},
	data() {
		return {
			stepProcessList:{
					stage_code:'',
					project_id:''
					},

			project_id: '',
			addFormData: {
				reasons_application: '',
				reasons_application_else: '',
				seal_category: '',
				qualification_category: '',
				quantity_printed: '',
				contract_amount: '',
				remark: ''
			},
			S_project_name: '',
			S_project_code: '',
			S_contacts: '',
			S_member: '',
			S_evaluators: '',
			isSubmit: true,
			detailsImgList: [],
			submitImgList: [],
			approval_remark: '',
			details_project_status: '',
			token: '',
			member_id: '',
			company_id: ''
		};
	},
	async onLoad(options) {
		this.token = uni.getStorageSync('btlh_process_token') || '';
		this.member_id = uni.getStorageSync('btlh_process_member_id') || '';
		this.company_id = uni.getStorageSync('bthl_process_LoginCompanyId') || '';

		this.details_project_status = options.details_project_status || '';
		this.project_id = options.project_id || '';
		if (this.project_id) {
			this.getProjectDetails();
		}
	},
	// 开启微信发送给朋友
	//#ifdef MP-WEIXIN
	onShareAppMessage() {
		return{
			title:this.addFormData.project_name,
			path:'/packageProject/pages/project/reportAnSeal/applyForSeal?project_id='+this.project_id+'&details_project_status='+this.details_project_status
		}
	},
	//#endif
	methods: {
		// 点击撤回
		async handleWithdraw(){
			const { data: res } = await this.$myRequest({
				url: 'Project/withdraw',
				method: 'GET',
				data: {
					member_id: this.member_id,
					token: this.token,
					company_id: this.company_id,
					project_id:this.project_id
				}
			});
			if (res.code != 200)
				return uni.showToast({
					title: res.datas.msg,
					icon: 'none'
				});
				uni.navigateBack({
					delta:1
				})
		},
		// 审批
		async handleExamine(val){
			const { data: res } = await this.$myRequest({
				url: 'Project/seal_approval',
				method: 'POST',
				data: {
					member_id: this.member_id,
					token: this.token,
					company_id: this.company_id,
			
					project_id: this.project_id,
					approval_status: val,
					remark: this.approval_remark
				}
			});
			if (res.code != 200)
				return uni.showToast({
					title: res.datas.msg,
					icon: 'none'
				});
			uni.showToast({
				title: res.datas.msg,
				icon: 'none'
			});
			/* uni.redirectTo({
				url: `/packageProject/pages/project/projectManagement`
			}); */
			uni.navigateBack({
				delta:1
			})
		},
		// 编辑提交
		async handleSubmit(val){
			if(this.date!='选择时间'){
				this.addFormData.notice_time = this.date
			}
			const { data: res } = await this.$myRequest({
				url: 'Project/seal',
				method: 'POST',
				data: {
					member_id: this.member_id,
					token: this.token,
					company_id: this.company_id,
					project_id: this.project_id,
			
					is_draft: val,
			
					annex: JSON.stringify(this.submitImgList),
					
					reasons_application: this.addFormData.reasons_application,
					reasons_application_else: this.addFormData.reasons_application_else,
					seal_category: this.addFormData.seal_category,
					qualification_category: this.addFormData.qualification_category,
					
					quantity_printed: this.addFormData.quantity_printed,
					remark: this.addFormData.remark,
				}
			});
			if (res.code != 200)
				return uni.showToast({
					title: res.datas.msg,
					icon: 'none'
				});
			uni.showToast({
				title: res.datas.msg,
				icon: 'none'
			});
			/* uni.redirectTo({
				url: `/packageProject/pages/project/projectManagement`
			}); */
			uni.navigateBack({
				delta:1
			})
		},
		// 获取详情
		async getProjectDetails() {
			const { data: res } = await this.$myRequest({
				url: 'Project/seal_detail',
				method: 'POST',
				data: {
					member_id: this.member_id,
					token: this.token,
					company_id: this.company_id,

					project_id: this.project_id
				}
			});
			if (res.code != 200)
				return uni.showToast({
					title: res.datas.msg,
					icon: 'none'
				});
			// 判断是否首次进入次流程
			if (res.datas.info.is_new != 1) {
				this.addFormData = res.datas.info;
			}else{
				this.addFormData.is_edit = res.datas.info.is_edit
			}
			// 判断禁用
			if (this.addFormData.is_draft != '1' && this.addFormData.is_edit == '1') {
				this.isSubmit = false;
			}
			this.stepProcessList.project_id = this.addFormData.project_id;
			this.stepProcessList.stage_code = this.addFormData.project_status;
			// 禁用值
			this.S_project_code = res.datas.info.project_code;
			this.S_project_name = res.datas.info.project_name;
			this.S_contacts = res.datas.info.contacts;
			res.datas.info.approval_member.forEach(item => {
				this.S_member += item.nickname + ' ';
			});
			this.S_evaluators = res.datas.info.evaluators.nickname;

			// 处理文件
			if (this.addFormData.annex) {
				this.detailsImgList = this.addFormData.annex;
				this.submitImgList = this.addFormData.annex;
			}

			console.log('外部审查', this.addFormData);
		},
		handleProjectTypeChange1(e){
			this.addFormData.reasons_application = e.detail.value
			if(this.addFormData.reasons_application!='-1'){
				this.addFormData.reasons_application_else=''
			}
		},
		handleProjectTypeChange2(e){
			this.addFormData.seal_category = e.detail.value
		},
		handleProjectTypeChange3(e){
			this.addFormData.qualification_category = e.detail.value
		},
		// 文件上传
		upLoadChange(data) {
			console.log('文件列表', data);
			this.submitImgList = data;
		},
		// 点击返回
		back() {
			// uni.navigateBack({
			// 	delta: 1
			// });
			uni.redirectTo({
				url:'/packageProject/pages/project/projectManagement'
			})
		}
	},
	computed: {
		isTypeInputDis() {
			if (this.addFormData.reasons_application == '-1') {
				return true;
			} else {
				return false;
			}
		}
	}
};
</script>

<style lang="scss">
	.bottom2 {
			width: 100%;
		}
	.bottom_btn2 {
			width: 34%;
			height: 88rpx;
			border-radius: 0;
			position: fixed;
			bottom: 0;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
			z-index: 999;
		}	
	
	.textera{
		width: 690rpx;
		height: 305rpx;
		background: #F7F7F7;
		padding-top: 20rpx;
		padding-bottom: 20rpx;
	}
	
.radioRow{
	display: flex;
	align-items: flex-start;
	.radioRowtitle{
		width: 150rpx;
		display: block;
	}
}
.radio_text {
	font-size: 28rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #666666;
}
.textar {
	width: 690rpx;
	height: 305rpx;
	background: #f7f7f7;
	margin-top: 30rpx;
	padding-top: 20rpx;
	padding-bottom: 20rpx;
	.holder {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
	}
}
.radio {
	width: 540rpx;
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	justify-content: flex-start;
}
.fbtn {
	position: fixed;
	left: 592rpx;
	bottom: 120rpx;
	z-index: 5;

	image {
		width: 134rpx;
		height: 134rpx;
	}
}

.file_name {
	font-size: 26rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #999999;
	margin-left: 19rpx;
}

.uptext {
	font-size: 20rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #128bf1;
	margin-left: 10rpx;
}

.bottom {
	width: 100%;
	z-index: 999;
	position: fixed;
	bottom: 0;
}

.bottom_btn {
	width: 375rpx;
	height: 88rpx;
	margin-left: 0;
	border-radius: 0;
	font-size: 32rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #ffffff;
}

.info_item {
	width: 690rpx;
	height: auto;
	border-bottom: 1rpx solid #e3e3e3;
	margin-left: 30rpx;
	margin-top: 44rpx;
}

.head_text {
	width: 100%;
	height: 128rpx;
	font-size: 36rpx;
	font-family: PingFang SC;
	font-weight: bold;
	color: #333333;
	line-height: 160rpx;
	text-align: center;
}
</style>
